#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
using namespace std;

int fun(int n)
{
	int tmp = 0;
	while (n)
	{
		tmp += (n % 10) * (n % 10);
		n /= 10;
	}
	return tmp;
}

int main()
{
	int n = 0;
	cin >> n;
	int fast = fun(n), slow = n;

	while (fast != slow)
	{
		fast = fun(fast);
		fast = fun(fast);
		slow = fun(slow);

	}

	cout << (slow == 1) << endl;


	return 0;
}